import { createAction } from 'redux-actions'
import { check, body, delJson, getJson, postJson, putJson, parseJSON, checkStatus, data } from './util'

// 个人设置 - 提醒设置列表
export
const fetchRemindSettings = createAction('fetch remind settings', () =>
	fetch('/remind-settings', getJson)
		.then(checkStatus)
		.then(parseJSON)
		.then(check)
    .then(data)
)

// 个人设置 - 提醒设置更新
export
const updateRemindSettings = createAction('update remind settings', (arg, cb) =>
	fetch('/remind-settings', {
		...putJson,
		...body(arg)
	})
		.then(checkStatus)
		.then(parseJSON)
		.then(check)
		.then(cb)
)

export
const updatePassword = createAction('update password', (arg, cb) =>
	fetch('/auths/change-password', {
		...putJson,
		...body(arg)
	})
		.then(checkStatus)
		.then(parseJSON)
		.then(check)
		.then(cb)
)

export
const logout = createAction('logout', () =>
	fetch('/auths/login', postJson)
		.then(checkStatus)
		.then(parseJSON)
		.then(check)
		.then(cb)
)


export
const tranferRole = createAction('void', (arg,cb) =>
	fetch('/roles/tranfer-role', {
		...putJson,
		...body(arg)
	})
		.then(checkStatus)
		.then(parseJSON)
		.then(check)
		.then(cb)
)


